<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 数组解构

        // 1.数组中元素少,解构的变量多,变量默认UNDEFINED
        const [a,b,c,d] = [111,222,333];
        console.log(a,b,c,d);

        // 2.数组中元素多,解构的变量少,未赋值无效
        const [e,f] = [111,222,333];
        console.log(e,f);

        // 3.可以利用剩余参数,接收多余的数组元素
        const [g,h,...args] = [111,222,333,444];
        console.log(g,h,args);

        // 4.可以给解构的变量,设置默认值;
        //   默认值如果没有被赋值,就是默认状态;如果被赋值,会被覆盖掉;
        const [i,j=0,k=0] = [111,222];
        console.log(i,j,k);

        // 5.接收指定项
        const [l, , , m] = [111,222,333,444];
        console.log(l,m);

        // 6.多维数组的结构
        const [n,[o, p]] = [111,[222, 333]];
        console.log(n,o,p);

        
        // 对象解构

         // 1.对象里面套对象
        // const pig = {
        //     name: '佩奇',
        //     age: 6,
        //     family: {
        //         mother: '猪妈妈',
        //         father: '猪爸爸',
        //         brother: '乔治'
        //     }
        // }
        // // 如果是对象,需要指定解构那个属性
        // const { name, age, family: { mother, father, brother } } = pig
        // console.log(name, age, mother, father, brother);

         // 2.数组里面访对象,对象里面再放对象
        // const arr = [
        //     {
        //         name: '佩奇',
        //         age: 6,
        //         family: {
        //             mother: '猪妈妈',
        //             father: '猪爸爸',
        //             brother: '乔治'
        //         }
        //     }
        // ]
        // const [{name,age,family:{mother,father,brother}}] = arr
        // console.log(name,age,mother,father,brother);

        // 3.对象里面放数组(重点,必须掌握的)
        let obj = {
            code: 200,
            msg: '获取新闻列表成功',
            data: [
                { id: 1, title: '特大喜讯1...', count: 33 },
                { id: 2, title: '特大喜讯2...', count: 44 },
                { id: 3, title: '特大喜讯3...', count: 55 },
            ]
        }
        const {data:[id,title,count]} = obj
        console.log(id,title,count);
    </script>
</body>
</html>